package cc.comac.mom.datahandlers.entity.soapreceive;

import java.io.ByteArrayOutputStream;
import java.util.HashMap;
import java.util.Map;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;

import org.springframework.stereotype.Component;

import com.alibaba.ans.shaded.com.alibaba.fastjson.JSONObject;

import cc.comac.mom.util.soaputil.SoapCallUtil;

@Component
public class ConditionalSentMaterielReceive {

	// 当qar状态改变时，将改变的状态发送给有条件发料系统

	public void setQarStatus(String qarNumber, String status) {
		
		Map<String,Object> map = new HashMap<>();
		map.put("qar_number", qarNumber);
		map.put("status", status);
		String json = JSONObject.toJSONString(map);
		try {
			Map<String, Object> invoke2 = SoapCallUtil.invoke("http://10.14.3.83/pso/webService/services/IRCRService?wsdl", "updateQARState", json);
			if (!invoke2.get("flag").equals("true")) {
				throw new RuntimeException("有条件发料系统调用接口更新qar状态接口调用失败！");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	// 通过pi_id查询pi_id的状态
	/**
	 * QAR任务如果被标记为有条件发料，
	 * 当QAR任务需要提交审核时需要判断PI是否已经关闭，
	 * 如果没关则不能提交审核，关了才可以进行审核
	 * */
	public Map<String,Object> selectpiIdStatusBypiId(String piId) {
		
		Map<String,Object> hashMap = new HashMap<String, Object>();
		hashMap.put("Pi_Id", piId);
		String json = JSONObject.toJSONString(hashMap);
		Map<String, Object> invoke = null;
		try {
			invoke = SoapCallUtil.invoke("http://10.14.3.83/pso/webService/services/IRCRService?wsdl", "returnPIState", json);
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException("提交审核获取piId状态报错   "+e);
		}
		return invoke;
	}
	
	

}
